# import os
# import oss2

# from oss2.credentials import EnvironmentVariableCredentialsProvider
# # OSS
# # endpoit 内网：https://oss-cn-beijing-internal.aliyuncs.com 外网：oss-cn-beijing.aliyuncs.com
# # key LTAI5tLoYggocBbMJHHQMNF2
# # secret MTA8JKke9hjXeT25mu8dVzhKrm6141
# def upload_toss():
#     # 从环境变量中获取访问凭证。运行本代码示例之前，
#     # 请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
#     auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
#     os.environ["OSS_ACCESS_KEY_ID"] = "LTAI5tLoYggocBbMJHHQMNF2"
#     os.environ["OSS_ACCESS_KEY_SECRET"] = "MTA8JKke9hjXeT25mu8dVzhKrm6141"
#     endpoint = "https://oss-cn-beijing.aliyuncs.com"
#     region = "cn-beijing"
#     # bucket = oss2.Bucket(auth, 'https://oss-cn-beijing.aliyuncs.com', 'supmu')     #supmu是bucket
#     bucket = oss2.Bucket(auth, endpoint, "supmu", region=region)
#     # object_name = f'{output_dir}/' + file_name
#     object_name = "/Users/jinjiakk/Downloads/BIZ_5023736_产品方案_20250124 (4).docx"
#     # 尝试上传文件
#     result = bucket.put_object_from_file("/kwdb/BIZ_5023736_产品方案_20250124 (4).docx", "/Users/jinjiakk/Downloads")
#     print(result)
# upload_toss()

import oss2
# OSS
# endpoit 内网：https://oss-cn-beijing-internal.aliyuncs.com 外网：oss-cn-beijing.aliyuncs.com
# key LTAI5tLoYggocBbMJHHQMNF2
# secret MTA8JKke9hjXeT25mu8dVzhKrm6141

auth = oss2.Auth('LTAI5tLoYggocBbMJHHQMNF2', 'MTA8JKke9hjXeT25mu8dVzhKrm6141')
# auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
bucket = oss2.Bucket(auth, "https://oss-cn-beijing.aliyuncs.com", 'zmn-bigdata')
# bucket = oss2.Bucket(auth, "https://oss-cn-beijing-internal.aliyuncs.com", 'supmu')
print(bucket)
 
local_file_path = 'path/to/your/local/file'
local_file_path = "/Users/jinjiakk/Downloads/BIZ_5023736_产品方案_20250124 (4).docx"
oss_file_path = 'path/in/oss/bucket/your-file-name'
oss_file_path = "aidoc/BIZ_5024923_产品PRD_20241225.docx"

# # 上传文件
r = bucket.put_object_from_file(oss_file_path, local_file_path)
print(r)
print('File uploaded successfully.')
url = bucket.sign_url('GET',oss_file_path,36000)
print(url)
# print(r)
# files = oss2.ObjectIterator(bucket)
# for _ in files:
#     print(_)



# https://zmn-bigdata.oss-cn-beijing.aliyuncs.com/aidoc%2FBIZ_5022945_%E4%BA%A7%E5%93%81%E6%96%B9%E6%A1%88%E8%AE%BE%E8%AE%A1_20250115.docx?OSSAccessKeyId=LTAI5tLoYggocBbMJHHQMNF2&Expires=1740658943&Signature=tGIVSJik6SC5M7mvVrTxc1IHVzs%3D
# https://zmn-bigdata.oss-cn-beijing.aliyuncs.com/aidoc%2FBIZ_5023736_%E4%BA%A7%E5%93%81%E6%96%B9%E6%A1%88_20250124.docx?OSSAccessKeyId=LTAI5tLoYggocBbMJHHQMNF2&Expires=1740660724&Signature=b6KYx2NfzDhMZtx4IOIw4alEC2o%3D
# https://zmn-bigdata.oss-cn-beijing.aliyuncs.com/aidoc%2FBIZ_5024923_%E4%BA%A7%E5%93%81PRD_20241225.docx?OSSAccessKeyId=LTAI5tLoYggocBbMJHHQMNF2&Expires=1740661555&Signature=WNVNkxI3I8dFEIUtZBcEunizwSk%3D